#include <2025Linux.h>
#include <mysql/mysql.h> // 包含mysql的头文件
int main(int argc, char *argv[])
{
    MYSQL * conn = mysql_init(NULL); //给连接分配内存
    if(conn == NULL){
        fprintf(stderr,"mysql_init error: %s\n", mysql_error(conn));
        return -1;
    }
    MYSQL * ret =  mysql_real_connect(conn,
                       "localhost",
                       "root",
                       "123",//写自己的密码
                       "2025linux",//自己的database
                       0,NULL,0);
    if(ret == NULL){
        fprintf(stderr,"mysql_real_connect error: %s\n", mysql_error(conn));
        return -1;
    }

    //char sql[4096] = "insert into pet values ('Whislter','Gwen','bird',NULL,'1997-12-09',NULL);";
    char sql[4096] = {0};
    char name[] = "Whislter";
    char owner[] = "Gwen";
    char species[] = "bird";
    char birth[] = "1997-12-09";
    sprintf(sql,"insert into pet values ('%s','%s','%s',NULL,'%s',NULL);",name,owner,species,birth);

    int qret = mysql_query(ret,sql);//执行sql语句
    if(qret != 0){
        fprintf(stderr,"mysql_query error:%s\n", mysql_error(ret));
        return -1;
    }
    mysql_close(conn);
    return 0;
}

